package com.itheima.demo;

import java.util.ArrayList;
import java.util.Collections;
import java.util.function.Predicate;
import java.util.stream.Stream;

public class Demo_Stream002 {
    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        Collections.addAll(list, 11, 12, 45, 67, 3, 9, 1);
        //获取stream流;
        //截取前两个元素的方法;
        //list.stream().limit(2).forEach(s-> System.out.println(s));
        //跳过元素的方法;
        //list.stream().skip(2).forEach(s-> System.out.println(s));
        //对流中的数据进行过滤的方法:filter;
        //list.stream().filter(new Predicate<Integer>() {
        //    @Override
        //    public boolean test(Integer integer) {
        //        return integer > 20;
        //    }
        //}).forEach(s -> System.out.println(s));
        //对流中的数据进行过滤的方法:filter;简写格式;
        //list.stream().filter(integer -> integer>20).forEach(s-> System.out.println(s));
        //将两个流合成一个流;
        //ArrayList<Integer> list2 = new ArrayList<>();
        //Collections.addAll(list2, 11, 12, 45, 67, 3, 9, 1);
        //Stream.concat(list.stream(),list2.stream()).forEach(s-> System.out.println(s));

        //终结方法;
        //forEach;
        list.stream().forEach(s-> System.out.println(s));
        //count方法;
        long count = list.stream().count();
        System.out.println(count);

        //map方法;
        list.stream().map(integer -> integer+"").forEach(s-> System.out.println(s));
    }
}
